#include "timer.h"

/*---------------------------------------------------------------------------*/
/*
 * Finally, the implementation of the simple timer library follows.
 */
//#ifdef _WIN32
//
//static int clock_time(void)
//{ return (int)GetTickCount(); }
//
//#else /* _WIN32 */
//
//static int clock_time(void)
//{
//  struct timeval tv;
//  struct timezone tz;
//  gettimeofday(&tv, &tz);
//  return tv.tv_sec * 1000 + tv.tv_usec / 1000;
//}
//
//#endif /* _WIN32 */

static s32 clock_time(void)
{
    return (s32)GetTickCount();
}

int timer_expired(struct timer *t)
{
    return clock_time() >= (s32)(t->start + t->interval);
}

void timer_set(struct timer *t, s32 interval)
{
    t->interval = interval;
    t->start = clock_time();
}
/*---------------------------------------------------------------------------*/


//static struct timer codelock_timer, input_timer;
//timer_set(&codelock_timer, 1000);
//PT_WAIT_UNTIL(pt, key_pressed() || timer_expired(&codelock_timer));


